//
//  ScoreAlertTools.swift
//  KeyboardAndEmoji
//
//  Created by AP020Mac mini on 2025/9/26.
//

import UIKit
import StoreKit
import UIKit

class ScoreAlertTools: NSObject {
    
    static let shared = ScoreAlertTools()
    
    private override init() {}
    
    func showAppReview() {
        if showCustomStyle() {
            justShowNewAppReview()
        } else {
            // Assuming AppIdPack is defined elsewhere
            let reviewUrlString = "itms-apps://itunes.apple.com/app/id\(KAppID)?action=write-review"
            Utility.openExternalLink(urlString: reviewUrlString)

        }
    }
    
    func justShowNewAppReview() {
        let vc = ScoreAlertViewController(params: nil)
        vc.finishBlock = { params in
            print("showAppReview call \(params)")
            if let isSubmit = params["isSubmit"] as? Bool,
               let rate = params["rate"] as? Int,
               isSubmit && rate > 3 {
                
                if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
                    SKStoreReviewController.requestReview(in: windowScene)
                }else {
                    SKStoreReviewController.requestReview()
                }
            }
        }
        
        // Assuming findCurrentVC is an extension method available
        if let currentVC = UIViewController.getCurrentShowTopVC() {
            currentVC.present(vc, animated: true, completion: nil)
        }
    }
    
    private func showCustomStyle() -> Bool {
       
        return true
//        return KAppDelegate?.appServerConfigModel.autoAd == "1"
    }
}
